<template>
  <vab-dialog v-model="isShowDialog" :close-on-click-modal="true" show-fullscreen width="80%">
    <template #default>
      <CommonForm
        ref="commonFormRef"
        v-model="form"
        v-loading="formLoading"
        :layout-config="layoutConfig"
        :option="option"
        @on-cancel="onHandleCancel"
      />
    </template>
  </vab-dialog>
</template>

<script>
import CommonForm from "@/plugins/form/CommonForm.vue";
import VabDialog from "@/plugins/VabDialog/index.vue";
import { TableColumnOrFormTypeEnum } from "@/plugins/commonType.enum";
import { getDetails } from "@/api/mains";
export default defineComponent({
  name: "PersonDetail",
  components: {
    CommonForm,
    VabDialog
  },
  emits: { "on-success": null },
  setup(props, { expose }) {
    const state = reactive({
      url: "system/person",
      isShowDialog: false,
      formLoading: false,
      layoutConfig: {
        //form组件布局
        column: 2
      }
    });

    const form = ref({});
    const option = {
      column: [
        {
          label: "所属机构",
          type: TableColumnOrFormTypeEnum.SELECTTREE,
          prop: "orgid",
          dictUrl: "system/org/query",
          placeholder: "请选择所属机构"
        },
        { label: "姓名", type: TableColumnOrFormTypeEnum.INPUT, prop: "name" },
        { label: "身份证号码", type: TableColumnOrFormTypeEnum.INPUT, prop: "idcard" },
        { label: "性别", type: TableColumnOrFormTypeEnum.SELECT, dictCode: "SexEnum", prop: "sex" },
        { label: "岗位", prop: "post", dictCode: "Post", width: 160 },
        { label: "岗位级别", prop: "postlevel", dictCode: "PostLevel", width: 160 },
        { label: "薪级", type: TableColumnOrFormTypeEnum.SELECT, dictCode: "SalaryLevel", prop: "salary" },
        { label: "学历", type: TableColumnOrFormTypeEnum.SELECT, dictCode: "Education", prop: "education" },
        { label: "手机号码", type: TableColumnOrFormTypeEnum.INPUT, prop: "mobile" },
        { label: "备注", type: TableColumnOrFormTypeEnum.TEXTAREA, prop: "memo", expand: 2 }
      ],
      formConfig: {
        title: "",
        isInModal: true,
        disabled: true
      },
      btnsConfig: {
        save: {
          isShow: false
        }
      },
      rules: {}
    };

    const showDialog = async row => {
      state.isShowDialog = true;
      if (row) {
        state.formLoading = true;
        const response = await getDetails(state.url, row.id);
        state.formLoading = false;
        form.value = response.data;
      } else {
        form.value = {};
      }
    };

    const onHandleCancel = () => {
      state.isShowDialog = false;
    };

    expose({ showDialog });
    return {
      ...toRefs(state),
      form,
      option,
      onHandleCancel
    };
  }
});
</script>
